const { isInstallWXIde } = require("./util");
const { req } = require("./req");
const { xcx } = require("../../config");
const idePort = require("./ide_port");
const getBaseUrl = () => {
	const port = idePort.getIdePort();
	return `http://127.0.0.1:${port}`;
};
// 打开工具或指定项目
exports.open = (projectPath = null) => {
	const option = {};
	option.url = getBaseUrl() + `/open`;
	if (projectPath) {
		option.qs = { projectPath };
	}
	return req(option);
};
//登录
exports.login = (projectPath = null) => {
	const option = {};
	option.url = getBaseUrl() + `/login`;
	option.qs = { format: "base64", resultoutput: xcx.loginTmp };
	return req(option);
};
//预览
/**
 * {
	format = "base64",
	projectpath = "",
	compilecondition = "",
	qroutput = "",
	infooutput = "",
}
 */
exports.preview = params => {
	params = Object.assign(
		{
			format: "base64",
		},
		params,
	);
	const option = {};
	option.url = getBaseUrl() + `/preview`;
	option.qs = params;
	return req(option);
};

/**
 * 上传
 * @params {Object} 参数
 * @returns {Promise}
 */
exports.upload = params => {
	params = Object.assign(
		{
			format: "base64",
		},
		params,
	);
	const option = {};
	option.url = getBaseUrl() + `/upload`;
	option.qs = params;
	return req(option);
};

/**
 * 关闭当前项目窗口
 * @returns {Promise}
 */
exports.close = param => {
	const option = {};
	option.url = getBaseUrl() + `/close`;
	option.qs = param;
	return req(option);
};
/**
 * 关闭开发者工具
 * @returns {Promise}
 */
exports.quit = () => {
	option.url = getBaseUrl() + `/quit`;
	return req(option);
};
